package com.cardvalue.sys.activity;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.alibaba.fastjson.JSON;
import com.cardvalue.sys.R;
import com.cardvalue.sys.cache.LocalCache;
import com.cardvalue.sys.entity.VerifyImgCode;
import com.cardvalue.sys.mode.UserService;
import com.cardvalue.sys.tool.MessageBox;
import com.cardvalue.sys.tool.Utiltools;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import lombok.Builder;

/**
 * 征信报告
 */
public class CreditReportActivity extends Activity {

    @Bind(R.id.credit_report_name)  EditText mName;//用户名
    @Bind(R.id.credit_report_password) EditText mPassword;//密码
    @Bind(R.id.credit_report_VertifyCode)  EditText mVertifyCode;//验证码
    @Bind(R.id.authentication_code) EditText  mAuthenticationCode;//身份验证码
    @Bind(R.id.iv_getCode) ImageView  ivgetCode;//图形验证码
    @Bind(R.id.submit) Button  mSubmit;//提交按钮

    private UserService userService;
    private String sessionId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_credit_report);
        ButterKnife.bind(this);
        userService=new UserService(this);
        getcreditReportVerifyCode();
    }


    @OnClick(R.id.submit)  void  onclickSubmit(){//征信第二步
        String  name=mName.getText().toString();
        String  password=mPassword.getText().toString();
        String  vertifyCode=mVertifyCode.getText().toString();
        String  authenticationCode=mAuthenticationCode.getText().toString();
        userService.CreditReport(name, password, vertifyCode, authenticationCode,LocalCache.getStringLocalData(CreditReportActivity.this,"sessionId"), new UserService.GetcreatVerityCodeCallback() {
            @Override
            public void success(VerifyImgCode verifyImgCode) {

            }

            @Override
            public void fail(VerifyImgCode verifyImgCode) {

            }

            @Override
            public void cancelDialog() {

            }
        });
    }

    /**
     * 征信报告的验证码
     */
    public void getcreditReportVerifyCode(){
        userService.creditReportVerifyCode(new UserService.GetcreatVerityCodeCallback() {
            @Override
            public void success(VerifyImgCode verifyImgCode) {
                    Utiltools.printE("verifyImgCode===222====", JSON.toJSONString(verifyImgCode)+"====");
                    ivgetCode.setImageURI(Uri.parse(verifyImgCode.getImgUrl()));
            }

            @Override
            public void fail(VerifyImgCode verifyImgCode) {

            }
            @Override
            public void cancelDialog() {

            }
        });
    }

}
